package tech.bmatch.redpack.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import tech.bmatch.redpack.model.RedPack;
import tech.bmatch.redpack.service.RedPackService;

import java.io.File;
import java.io.IOException;
import java.util.List;


/**
 * 将红包对象存储为json文件
 */
public abstract class RedPackServiceFileStoreImpl implements RedPackService {

    private static final Logger logger = (Logger) LoggerFactory.getLogger(RedPackServiceFileStoreImpl.class);
    private static ObjectMapper objectMapper = new ObjectMapper();
    private static File file = new File("./data.json");


    public void store(List<RedPack> redPackList) {
        if (redPackList == null) return;
        try {
            objectMapper.writeValue(file, redPackList);
        } catch (IOException e) {
            logger.error("write redPack from file error");
        }
    }

}
